package com.wzy.level.category.categoryServlet;

import com.wzy.Jdbc封装.pojo.News_category;
import com.wzy.Jdbc封装.pojo.News_user;
import com.wzy.level.category.categoryService.categoryService;
import com.wzy.level.category.categoryServiceImpl.categoryServiceImpl;
import com.wzy.level.user.userService.userService;
import com.wzy.level.user.userServiceImpl.userServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/category")
public class category extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        categoryService category = new categoryServiceImpl();
        List<News_category> news_category1 = category.selectAll();
        int total = news_category1.size();
        HttpSession session = req.getSession();
        int count = (int) session.getAttribute("count");

        session.setAttribute("total",total);
        int totalPage =0;//总页数
        try {
            totalPage = (int)total/count;
        }catch (Exception e){
            e.printStackTrace();
        }
        session.setAttribute("totalPage",totalPage);

//        List<News_user> news_users = (List<News_user>) session.getAttribute("news_user_byPage");
//        session.setAttribute("news_users",news_users);
        resp.sendRedirect(req.getContextPath()+"/system/category.jsp");
    }
}
